package translate;

import tree.BINOP;
//import tree.BasicExp;
import tree.BasicStm;
import tree.CJUMP;
import tree.CONST;
import tree.JUMP;
import tree.LABEL;
import tree.MOVE;
import tree.SEQ;
import tree.TEMP;

public class ForExp extends Nx {

	public ForExp(Exp i, Exp h, Exp b, Access iv, temp.Label lDone) {
		super(null);
		temp.Temp limit = new temp.Temp();
		temp.Label lTest = new temp.Label();
		temp.Label lBody = new temp.Label(); 
		
		BasicStm pro = new SEQ(i.unNx(), new MOVE(new TEMP(limit), h.unEx()));
		
//		BasicExp itrVar = iv.acc.exp(new TEMP(iv.home.frame.FP()));
		stm = new SEQ(
				pro, new SEQ(
						new LABEL(lTest),
						new SEQ(
							new CJUMP(CJUMP.LE, iv.acc.exp(new TEMP(iv.home.frame.FP())), new TEMP(limit), lBody, lDone), 
							new SEQ(
								new LABEL(lBody), 
								new SEQ(
									b.unNx(), 
									new SEQ(
										new MOVE(iv.acc.exp(new TEMP(iv.home.frame.FP())), new BINOP(BINOP.PLUS, iv.acc.exp(new TEMP(iv.home.frame.FP())), new CONST(1))),
										new SEQ(
											new JUMP(lTest),
											new LABEL(lDone)
										)
									)
								)
							)
						)
					)
			);
	}
	
}
